<?php
/**
 * Created by PhpStorm
 * User: Jhinwy
 * Date: 6/7/24
 * Time: 11:45 AM
 */

namespace App\Http\Controllers\Admin;


use App\Services\CustomerLinkService;
use Illuminate\Http\Request;
use App\Http\Controllers\ResourceController;

class CustomerLinkController extends ResourceController
{
    protected $service;

    public function __construct(CustomerLinkService $service)
    {
        $this->service = $service;
    }


    /**
     * 获取连接列表
     *
     * @param Request $request
     * @return mixed
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function getList(Request $request)
    {
        return $this->responseWithSuccess($this->service->getLinkList($request->post()));
    }


    /**
     * 创建获客链接
     *
     * @param Request $request
     * @return mixed
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function create(Request $request)
    {
        $result = $this->service->createLink($request->post());
        if (is_string($result)) {

            return $this->responseWithError($result);
        }

        return $result ? $this->responseWithSuccess() : $this->responseWithError();
    }


    /**
     * 删除获客链接
     *
     * @param Request $request
     * @return mixed
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function delete(Request $request)
    {
        $result = $this->service->deleteLink($request->post());
        if (is_string($result)) {

            return $this->responseWithError($result);
        }

        return $result ? $this->responseWithSuccess() : $this->responseWithError();
    }


    /**
     * 获取额度
     *
     * @param Request $request
     * @return mixed
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function getQuota(Request $request)
    {
        return $this->responseWithSuccess($this->service->getQuota($request->post('corp_id')));
    }
}
